<template>
  <div class="user">
    <div class="list">
      
         <avue-crud ref="crud" :option="option"  :data="data" :cell-style="cellStyle"  @row-click="rowClick"  >
           
        </avue-crud>
        <Alert :toSonData="res"  v-if="flag"   @close="rowClick"/>
    </div>
 
  </div>
</template>

<script>
import Alert from '../../../components/relstatus'
import axios from 'axios'
export default {
  name:"user",
  components:{
    Alert
  },
  data(){
    return {
      flag: false,
       page1: {
          currentPage: 1,
          total: 0,
          layout: "total,pager,prev, next",
          background:false,
          pageSize: 10
        },
       data:[
       ],
       option:{
          align: 'center',
          menuAlign: 'center',
          addBtn:false,
          menu:false,
          column: [
              {
              label: '书名',
              prop: 'name',
              cell: true

            },{
              label: '类型',
              prop: 'type',
              cell: true
            },{
              label: '出版社',
              prop: 'publisher',
              cell: true
            },{
              label: '数量',
              prop: 'inventory',
              cell: true
            },{
              label: '价钱',
              prop: 'price',
              cell: true
            },{
              label: '录入时间',
              prop: 'releasetime',
              type:'datetime',
              cell: true
            },{
              label: '审核状态',
              prop: 'title',
              className:"relsta",
              cell: true
            }
          ]
       },
       res:[]
    }
  },


  created(){
 
    this.getList()
   
  },
 methods: {

    rowClick(row) {
      console.log(row);
      this.res = row
      this.flag = row;
    },
    cellStyle({row,column,rowIndex,columnIndex}){
      if(columnIndex==6){
        if(row.relstatus == "0"){
          return {
            color:'rgba(0,0,0,0.5)',
          }
        }else if(row.relstatus == "1"){
          return {
            color:'rgb(21, 160, 255)'
          }
        }else{
          return {
            color:'red',
            
          }
        }
      }
    }
   ,
   getList() {
      axios.post('apis/pc_bookinfo').then(res=>{
        this.data = res.data.data
        this.data.forEach(item =>{
          item.title = this.numTolabel(item.relstatus)
          function rTime(date) {
              var json_date = new Date(date).toJSON();
              return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') 
          }
        let iTime= rTime(item.releasetime)
        item.releasetime = iTime;

        // 
        })
      })
      setTimeout(()=>{
         console.log(213123,this.data);
      })
     
   },
    numTolabel(value){
      let str ="";
      switch(value){
        case 1 :
          str = "通过"
          break;
        case 2 :
          str = "未通过"
          break;
        default :
          str = "未审核"
      }
      return str
    }
  },
  computer:{
   
  },
}
</script>

<style scoped>
  .list{
    width: 88%;
    padding: 20px;
    text-align: center;
  }

</style>